package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.MesEquipmentExamine;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.MesEquipmentExamineDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2022-03-30 15:25:36
 */
public class MesEquipmentExamineConverts {

    private static Logger LOG = LoggerFactory.getLogger(MesEquipmentExamineConverts.class);

    public static List<MesEquipmentExamineDTO> convert(List<MesEquipmentExamine> mesEquipmentExamineList) {
        if (CollectionUtils.isEmpty(mesEquipmentExamineList)) {
            return Collections.EMPTY_LIST;
        }

        List<MesEquipmentExamineDTO> mesEquipmentExamineListResult = Lists.newArrayList();
        for (MesEquipmentExamine mesEquipmentExamine : mesEquipmentExamineList) {
            mesEquipmentExamineListResult.add(convert(mesEquipmentExamine));
        }
        return mesEquipmentExamineListResult;
    }

    public static MesEquipmentExamineDTO convert(MesEquipmentExamine mesEquipmentExamine) {
        try {
            return BeanUtils.copy(mesEquipmentExamine, MesEquipmentExamineDTO.class);
        } catch (Exception e) {
            LOG.error("MesEquipmentExamine到MesEquipmentExamineDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesEquipmentExamine到MesEquipmentExamineDTO转换失败", e);
        }
    }

    public static MesEquipmentExamine convert(MesEquipmentExamineDTO mesEquipmentExamineDTO) {
        try {
            return BeanUtils.copy(mesEquipmentExamineDTO, MesEquipmentExamine.class);
        } catch (Exception e) {
            LOG.error("MesEquipmentExamineDTO到MesEquipmentExamine转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "MesEquipmentExamineDTO到MesEquipmentExamine转换失败", e);
        }
    }
}